#ifndef _OCX_CALL_FLASH_ARGUMENT_ENCODE_H_
#define _OCX_CALL_FLASH_ARGUMENT_ENCODE_H_
#include <string>
class CCallFlashArgumentEncode
{
	std::basic_string<WCHAR> m_EncodeString;
	std::basic_string<WCHAR> m_resultString;
	std::basic_string<WCHAR> m_functionName;
	bool	m_bModified;
public:
	CCallFlashArgumentEncode()
	{
		clear();
	}
	virtual ~CCallFlashArgumentEncode()
	{
	}
	void clear()
	{
		m_EncodeString.clear();
		m_resultString.clear();
		m_bModified = true;
	}
	void setName(LPCWSTR pFunName)
	{
		m_functionName = pFunName;
	}
	void pushArg(VARIANT * var)
	{
		
		switch(var->vt)
		{
		case VT_BSTR:
			{
				m_EncodeString+=L"<string>";
				if(lstrlen(var->bstrVal))
				{
					m_EncodeString+=var->bstrVal;
				}
				else
					m_EncodeString+=L"null";
				m_EncodeString+=L"</string>";
			}
			break;
		case VT_R4:
			{
				WCHAR szNumber[21] = {0};
				swprintf_s(szNumber,20,L"%f",var->fltVal);
				m_EncodeString+=L"<number>";
				m_EncodeString+=szNumber;
				m_EncodeString+=L"</number>";
			}
			break;
		case VT_R8:
			{
				WCHAR szNumber[21] = {0};
				swprintf_s(szNumber,20,L"%lf",var->dblVal);
				m_EncodeString+=L"<number>";
				m_EncodeString+=szNumber;
				m_EncodeString+=L"</number>";
			}
			break;
		case VT_UI4:
			{
				WCHAR szUint[21] = {0};
				swprintf_s(szUint,20,L"%ud",var->uintVal);
				m_EncodeString+=L"<number>";
				m_EncodeString+=szUint;
				m_EncodeString+=L"</number>";
			}
			break;
		case VT_I4:
			{
				WCHAR szInt[21] = {0};
				swprintf_s(szInt,20,L"%d",var->intVal);
				m_EncodeString+=L"<number>";
				m_EncodeString+=szInt;
				m_EncodeString+=L"</number>";
			}
			break;
		case VT_BOOL:
			{
				m_EncodeString+=L"<boolean>";
				m_EncodeString+=var->boolVal?L"true":L"false";
				m_EncodeString+=L"</boolean>";
			}
			break;
		case VT_EMPTY:
			{
				m_EncodeString+=L"<undefined/>";
			}
			break;
		default:
			return;
		}
		m_bModified = true;
	}
	LPCWSTR getEncodeString()
	{
		if(m_bModified)
		{
			m_resultString = L"<invoke name=\"";
			if(m_EncodeString.size())
			{
				m_resultString += m_functionName;
				m_resultString += L"\" returntype=\"xml\"><arguments>";
				m_resultString +=m_EncodeString;
				m_resultString += L"</arguments></invoke>";
			}
			else
			{
				m_resultString += m_functionName;
				m_resultString += L"\" returntype=\"xml\">";
				m_resultString += L"</invoke>";
			}
			m_bModified = false;
		}
		return m_resultString.c_str();
	}
};


#endif//_OCX_CALL_FLASH_ARGUMENT_ENCODE_H_